package edu.tju.honour;


import java.sql.SQLException;
import java.util.Date;




import org.infohazard.maverick.flow.ControllerContext;

import com.younker.waf.maverick.DispatchCtl;


import edu.tju.teacherManagement.ITeacherDao;
import edu.tju.teacherManagement.IbatisTeacherDao;
import edu.tju.teacherManagement.Teacher;




public class HonourSetAction extends DispatchCtl{
	
	private final static String SUCCESS = "success";


	protected Object makeFormBean(ControllerContext arg0) {
		
		return new HonourSetAction();
	}
	private long id;
	
	private String glory;
	
	private Date setTime;
	
	private Teacher teacher;
	

	public String getGlory() {
		return glory;
	}
	public void setGlory(String glory) {
		this.glory = glory;
	}
	public Teacher getTeacher() {
		return teacher;
	}
	public void setTeacher(Teacher teacher) {
		this.teacher = teacher;
	}
	public long getId() {
		return id;
	}
	public void setId(long id) {
		this.id = id;
	}
	



	public Date getSetTime() {
		return setTime;
	}
	public void setSetTime(Date setTime) {
		this.setTime = setTime;
	}
	ITeacherDao teacherDao=new IbatisTeacherDao();
	public  String getTeacherById(Object formBean, ControllerContext ctx)throws SQLException {
		
		HonourSetAction bean = (HonourSetAction) formBean;
		Teacher teacher=teacherDao.getTeacherById(bean.getId());

		bean.setTeacher(teacher);

			return SUCCESS;
		}
	IHonourDao honourDao=new IbatisHonourDao();
	public  String insertHonour(Object formBean, ControllerContext ctx)throws SQLException {
		HonourSetAction bean = (HonourSetAction) formBean;
		Honour honour =new Honour();
		honour.setGlory(bean.getGlory());
		honour.setSetTime(bean.getSetTime());
		honour.setTeacherId(bean.getId());
		honourDao.insertHonour(honour);
		ctx.getRequest().setAttribute(RET_CODE, RC_SUCCESS);
		return SUCCESS;

	}
	public  String deleteHonourById(Object formBean, ControllerContext ctx)throws SQLException {
		HonourSetAction bean = (HonourSetAction) formBean;
		honourDao.deleteHonour(bean.getId());
		ctx.getRequest().setAttribute(RET_CODE, RC_SUCCESS);
		return SUCCESS;
	}
	
}
	
